package com.hllxd.hism.star.basic.service.exception;

import java.text.MessageFormat;

/**
 * @author xiyong.lxy
 * @date 2020-4-23 18:52
 */

public class BusinessException extends RuntimeException  {
    static final long serialVersionUID = 7818375828146090155L;

    public String code;
    public String msg;

    public BusinessException() {
        super();
    }

    public BusinessException(String code, String message) {
        super(message);
        this.code = code;
        this.msg = message;
    }

    public BusinessException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.msg = message;
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(BasicErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.msg = errorCode.getMessage();
    }

    public BusinessException(BasicErrorCode errorCode, Object... values) {
        super(MessageFormat.format(errorCode.getMessage(), values));

        this.code = errorCode.getCode();
        this.msg = MessageFormat.format(errorCode.getMessage(), values);
    }
}
